﻿using System.Text.RegularExpressions;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using QDT.Common;
using QDT.Common.Plugins;
using QDT.Core.Members;
using QDT.Core.MSData;


namespace QDT.Web.Moblie.Controllers
{
    public class ValicodeController : BaseController
    {
        //
        // GET: /Valicode/

        public ActionResult Image()
        {
            var vCode = IoC.Resolve<ValidateImage>();
            var code = vCode.CreateValidateCode(4);
            var cookie = new HttpCookie("valicode") { Value = code.Hash().Hash() };
            Response.AppendCookie(cookie);
            var bytes = vCode.CreateValidateGraphic(code);
            return File(bytes, @"image/jpeg");
        }


        public ActionResult Ajax_IsExist(string name)
        {
            var pattern = new Regex(@"^1[3-9][0-9]\d{8}$");
            if (!name.Match(pattern)) return Json(new { Status = -1, Info = "不正确" });

            var isHas = DbProvider.D<User>().Any(x => x.Mobile == name && x.MobilePassed);
            if (isHas) return Json(new { Status = 1, Info = "已存在" });
            return Json(new { Status = 0, Info = "可用" });
        }


    }
}
